<%-- 
    Document   : Login
    Created on : Jul 20, 2013, 11:23:41 PM
    Author     : Ndnam
--%>

<%@page import="classes.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Log in</title>
    </head>
    <body>
        <form method="POST">
            Username: <input type="text" name="username"><br>
            Password: <input type="password" name="password"><br>
            <input type="submit" value="OK">
        </form>
    </body>
</html>

<jsp:useBean id="auctionDAO" class="classes.AuctionDAO"/>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if (username != null && password != null) {
        String message = "";
        User user = auctionDAO.searchUserByUsername(username);
        if (user == null) {
            message = "Username does not exist";
        } else if (!password.equals(user.getPassword())) {
            message = "Password is not correct";
        } else {
            session.setAttribute("user", user);
            RequestDispatcher dispatch = request.getRequestDispatcher("Home.jsp");
            dispatch.forward(request, response);
            message = "Logged in successfully";
        }
        out.println(message);
    }
%>